package com.myk.game.gobangchess.dates;

import com.myk.game.gobangchess.Account;
import com.myk.game.gobangchess.constants.ChatLevel;
import com.myk.game.gobangchess.constants.PathCost;
import com.myk.game.gobangchess.utils.FileUtils;

import java.util.ArrayList;
import java.util.List;

public class ChatData {

    public static final List<String> PRE_CHAT_MESSAGE_LIST = new ArrayList<>();

    /**
     * 加载预设聊天消息列表
     */
    public static void loadPreMessageData() {
        if (FileUtils.isFileExists(PathCost.PRE_CHAT_MESSAGE_FILE)) {
            PRE_CHAT_MESSAGE_LIST.addAll(FileUtils.readFile2List(PathCost.PRE_CHAT_MESSAGE_FILE));
        }
    }

    /**
     * 获取聊天调整详情
     */
    public static String getChatAdjustDetail(Account account) {
        String curChatLevel = AccountData.getChatLevel(account);
        List<ChatLevel> chatLevelList = new ArrayList<>();
        chatLevelList.add(ChatLevel.PRESET);
        chatLevelList.add(ChatLevel.FREE);
        chatLevelList.add(ChatLevel.BAN);
        StringBuilder stringBuilder = new StringBuilder();
        for (ChatLevel chatLevel : chatLevelList) {
            stringBuilder.append(chatLevel.getLevel()).append(",").append(chatLevel.getDesc()).append(";");
        }
        stringBuilder.deleteCharAt(stringBuilder.length() - 1);
        return account.getIdCode() + "&" + account.getNickName() + "&" + curChatLevel + "&" + stringBuilder;
    }

    //修改用户聊天权限等级
    public static void changeChatLevel(Account account, int chatLevel) {
        AccountData.updatePlayerChatLevel(account.getIdCode(), account.getNickName(), chatLevel);
    }
}
